package com.android.questions.ui.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Paint;
import android.view.View;
import android.widget.CompoundButton;

import androidx.viewbinding.ViewBinding;

import com.android.base.ui.base.VBBaseActivity;
import com.android.base.util.ActivityClickUtil;
import com.android.base.util.Mmkv;
import com.android.base.util.SystemUtil;
import com.android.questions.R;
import com.android.questions.config.AppConfig;
import com.android.questions.databinding.ActivityAboutBinding;
import com.qq.e.o.HXADConfig;

/**
 * FileName: AboutActivity
 * Author: admin
 * Date: 2021/11/1 18:35
 * Description:
 */
public class AboutActivity extends VBBaseActivity implements View.OnClickListener {

    private ActivityAboutBinding aboutBinding;
    private static final String AD_RECOMMEND = "ad_recommend";

    public static void startActivity(Activity activity) {
        Intent intent = new Intent(activity, AboutActivity.class);
        activity.startActivity(intent);
    }

    @Override
    public ViewBinding getViewBinding() {
        setTitleBackground(BG_WHITE);
        return aboutBinding = ActivityAboutBinding.inflate(getLayoutInflater());
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void initView() {
        super.initView();
        ActivityClickUtil.getInstance().clear();

        aboutBinding.tvTitle.setText("关于我们");
        aboutBinding.tvVersion.setText(getString(R.string.app_name) + "  v:" + SystemUtil.getVersionName(this));
        aboutBinding.labelQq.setText("官方QQ群：" + AppConfig.QQ_GROUP);

        aboutBinding.switchAdRecommend.setChecked(Mmkv.getBoolean(AD_RECOMMEND));

        aboutBinding.tvUser.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        aboutBinding.tvPolicy.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
    }

    @Override
    public void initLister() {
        super.initLister();
        aboutBinding.imgBack.setOnClickListener(this);
        aboutBinding.tvUser.setOnClickListener(this);
        aboutBinding.tvPolicy.setOnClickListener(this);
        aboutBinding.ivJoinQqGroup.setOnClickListener(this);

        aboutBinding.switchAdRecommend.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                Mmkv.setBoolean(AD_RECOMMEND, b);
                HXADConfig.setPersonalizedSwitch(b);
            }
        });
    }

    @Override
    public void onClick(View v) {
        if (ActivityClickUtil.getInstance().isFastClick()) {
            //防止用户快速点击
            return;
        }
        if (v.getId() == R.id.imgBack) {
            finish();
        } else if (v.getId() == R.id.tvUser) {
            UserServiceAgreementActivity.startAct(this, UserServiceAgreementActivity.TYPE_USER);
        } else if (v.getId() == R.id.tvPolicy) {
            UserServiceAgreementActivity.startAct(this, UserServiceAgreementActivity.TYPE_PRIVACY);
        } else if (v.getId() == R.id.iv_join_qq_group) {
            SystemUtil.joinQQGroup(AboutActivity.this, AppConfig.QQ_GROUP_KEY);
        }
    }
}